package com.hymall.bean.vo;

import com.hymall.bean.MarketCart;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description 返回中间类
 * @Author 徐成喜
 * @Data 2022/7/19 15:08
 */

public class WxCartTool {

    public static WxCartIndexVO getCartIndexVO(List<MarketCart> marketCarts){

        WxCartIndexVO wxCartIndexVO = new WxCartIndexVO();
        WxCartTotalVO cartTotalVO = new WxCartTotalVO();
        Integer goodsCount = 0;
        Integer checkedGoodsCount =0 ;
        BigDecimal goodsAmount = new BigDecimal(0);
        BigDecimal checkedGoodsAmount = new BigDecimal(0);
        for (MarketCart marketCart : marketCarts) {

            //获取goodsCount
            goodsCount+=marketCart.getNumber();

            //获取goodsAmount
            BigDecimal number = new BigDecimal(marketCart.getNumber());
            BigDecimal price = new BigDecimal(String.valueOf(marketCart.getPrice()));
            BigDecimal multiply = number.multiply(price);
            goodsAmount = goodsAmount.add(multiply);

            if(marketCart.getChecked()==true){
                //获取checkedGoodsCount
                checkedGoodsCount+= marketCart.getNumber();

                //获取checkedGoodsAmount
                BigDecimal numberCheck = new BigDecimal(marketCart.getNumber());
                BigDecimal priceCheck = new BigDecimal(String.valueOf(marketCart.getPrice()));
                BigDecimal multiplyCheck = numberCheck.multiply(priceCheck);
                checkedGoodsAmount = checkedGoodsAmount.add(multiplyCheck);

            }
        }

        cartTotalVO.setGoodsCount(goodsCount);
        cartTotalVO.setGoodsAmount(goodsAmount);
        cartTotalVO.setCheckedGoodsCount(checkedGoodsCount);
        cartTotalVO.setCheckedGoodsAmount(checkedGoodsAmount);

        wxCartIndexVO.setCartTotal(cartTotalVO);
        wxCartIndexVO.setCartList(marketCarts);

        return wxCartIndexVO;

    }
}
